package com.ftwj.demo.generate.utils;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.yaml.snakeyaml.Yaml;
import com.ftwj.demo.generate.entity.Configuration;

import cn.hutool.core.util.ObjectUtil;

import java.io.InputStream;
import java.net.URL;


/**
*
* <p>Title: ConfigUtil</p>  
* <p>Description: 读取Yaml配置文件</p>
* <p>Copyright: Copyright (c) 2020 </p>  
* @author WangSLi
* @date 2020年2月28日 上午12:24:16
* @version V1.0
 */
public class ConfigUtil {
	
	private static final Logger logger=LoggerFactory.getLogger(ConfigUtil.class);
    private static Configuration configuration;

    static {
        URL url = ConfigUtil.class.getClassLoader().getResource("generate.yaml");
        if(ObjectUtil.isNotEmpty(url)) {
        	InputStream inputStream = ConfigUtil.class.getClassLoader().getResourceAsStream("generate.yaml");
        	Yaml yaml = new Yaml();
        	configuration = yaml.loadAs(inputStream, Configuration.class);
        }else {
        	logger.error("无法读取到文件 'generate.yaml'，请确认是文件是否存在！");
        }
    }

    public static Configuration getConfiguration() {
        return configuration;
    }
    
}
